var layer;
var $;
var element;
var form;
var laydate;
var table;
layui.use(['element','layer','laydate','form','table'], function(){
    layer = layui.layer;
    $ = layui.jquery;
    element = layui.element;
    form = layui.form;
    laydate = layui.laydate;
    table = layui.table;
    //执行一个laydate实例
    laydate.render({
        elem: '#createDate', //指定元素
        type: 'date',
        trigger: 'click' //时间时间为点击事件
    });
    load();
    selIndexUserTab();
})
/**
 *  点击事件  刷新  返回
 *  高级检索
 * */
function load(){
    $(".tit_btn").bind('click',function(){
        location.reload();
    })
    //点击搜索
    $("#index_btn").bind('click',function(){
        selIndexUserTab();
    })
}

/**
 *  检索用户列表
 */
function selIndexUserTab(){
    var vals = '';
    var trueName = $("input[name=trueName]").val();
    if(!trueName){
        vals+="&trueName="+''
    }else{
        vals+="&trueName="+trueName
    }
    var nickname = $("input[name=nickname]").val();
    if(!nickname){
        vals+="&nickname="+''
    }else{
        vals+="&nickname="+nickname
    }
    var account = $("input[name=account]").val();
    if(!account){
        vals+="&account="+''
    }else{
        vals+="&account="+account
    }
    var createDate = $("input[name=createDate]").val();
    if(!createDate){
        vals+="&createDate="+''
    }else{
        vals+="&createDate="+createDate
    }
    var type = $("select[name=type]").val();
    if(!type){
        vals+="&type="+''
    }else{
        vals+="&type="+type
    }
    $.ajax({
        url:"/personnel/selClosureLog",
        type:"post",
        dataType:"json",
        data:vals,
        success:function(item) {
            userTab(item.data);
        }
    })
}

/**
 * 查看封号日志列表
 * @param item
 */
function userTab(item){
    table.render({
        elem:"#userListTab",//容器
        title:"封号日志数据列表",
        data:item,
        toolbar:true,
        page:true,
        cols:[[//定义列
            {type:'checkbox',align:'center',width:40},//复选框靠左
            {title:'序号',align:'center',width:60, templet:function(data){
                    return data.LAY_INDEX;
                }},
            {field:"trueName",title:"管理员名称",align:'center',width:180},
            {field:"account",title:"用户账号",align:'center',width:180},
            {field:"nickname",title:"用户昵称",align:'center',width:180},
            {field:"createDate",title:"执行时间",align:'center',width:180},
            {field:"type",title:"类型",align:'center',width:120,templet:function(data){
                    if(data.type==2){
                        return "封号";
                    }else if(data.type==3){
                        return "解封";
                    }
                }},
            {field:"remark",title:"解封备注",align:'center',width:200},
            {field:"",title:"操作",align:'center',templet:function(data){
                    return "<a style='color:#009688;cursor:pointer;' onclick='delClosureLog(\""+data.id+"\")'>删除</a>  ";
            }}
        ]]
    });
}
/**
 * 点击删除日志
 * @param id
 */
function delClosureLog(id){
    $.post("/personnel/delClosureLog", {id:id}, function (res) {
       if(res){
           /* var tablename = "封号日志数据列表";
            var type=3;
            var remark = id+"";
            addOperLog(tablename,type,remark);*/
            layer.msg("删除成功",{icon:1});
            selIndexUserTab();
        }
    });
}
/**
 *  添加后台操作日志
 * */

function addOperLog(tablename,type,remark){
    var create=localStorage.getItem("user");
    create=JSON.parse(create);//将获取json字符串转json对象
    var mid = create.user_id;
    form+="&mid="+mid;
    form+="&tablename="+tablename;
    form+="&type="+type;
    form+="&remark="+remark;
    $.post("/personnel/addOperationLog", form, function (res) {
        form="";
    });
}
